package com.iee.lambda.optional;

import com.iee.common.entity.User;
import org.junit.Test;

import java.util.Optional;

/**
 *@ClassName OptionalTest2
 *@Description TODO
 *@Author longxiaonan@163.com
 *@Date 2022/5/7 0007 17:47
 */
public class OptionalTest2 {

    @Test
    public void test() {
//        User user = null;
        User user = new User();
        user.setName("xiaonan");
        user = Optional.ofNullable(user).orElse(createUser());
        System.out.println(user);
        user = Optional.ofNullable(user).orElseGet(() -> createUser());
        System.out.println(user);

    }
    public User createUser(){
        User user = new User();
        user.setName("zhangsan");
        return user;
    }
}
